package com.glory.study.webapi.controller;

import com.glory.study.model.GroupIdInfo;
import com.glory.study.service.GroupIdInfoService;
import com.alibaba.dubbo.config.annotation.Reference;
import com.glory.study.testinterface.HelloService;
import com.glory.study.testinterface.PayInfo;
import com.glory.study.testinterface.PayResult;
import com.glory.study.utils.PayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DubboConfigController {

    @Autowired
    private GroupIdInfoService groupIdInfoService;



    @Value("${dubbo.registry.address}")
    private String address;
    @Value("${demo.service.version}")
    private String version;


    @Reference(version = "${demo.service.version}",group = "pay1")
    private HelloService helloService;

    @RequestMapping("/dubbotest/{name}")
    public String sayHello(@PathVariable("name") String name) {
        return helloService.sayHello(name);

    }
    @RequestMapping("/dubbotest3/{name}")
    public PayResult dubbotest3(@PathVariable("name") String name) {
        PayInfo p=new PayInfo();
        return helloService.pay(p);

    }

    @RequestMapping("/dubbotest1")
    public PayResult dubbotest1() {

        PayInfo p=new PayInfo();
        p.setAddress(address);
        p.setVersion(version);
        p.setType("pay1");
        return PayUtils.invoke(p);

    }
    @RequestMapping("/dubbotest2")
    public PayResult dubbotest2() {
        PayInfo p=new PayInfo();
        p.setAddress(address);
        p.setVersion(version);
        p.setType("pay2");
        return PayUtils.invoke(p);
    }


    @RequestMapping("/dubboConfig1/{id}")
    GroupIdInfo finddubboConfig1(@PathVariable("id") Integer id) throws Exception{
       return groupIdInfoService.findById1(id);
    }

    @RequestMapping("/dubboConfig2/{id}")
    GroupIdInfo finddubboConfig2(@PathVariable("id") Integer id) throws Exception{
        return groupIdInfoService.findById2(id);
    }



}
